package cn.qn.controller.sys;

import cn.qn.dto.ResponseDTO;
import cn.qn.moudle.sys.Area;
import cn.qn.moudle.sys.City;
import cn.qn.moudle.sys.Province;
import cn.qn.service.sys.AreaService;
import cn.qn.service.sys.CityService;
import cn.qn.service.sys.ProvinceService;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api("系统省市区接口")
@RequestMapping("/sys")
public class ProvinceController {

    @Reference(check = false)
    private ProvinceService provinceService;
    @Reference(check = false)
    private CityService cityService;
    @Reference(check = false)
    private AreaService areaService;

    @RequestMapping(value = "/provinces", name = "获取所有省", method = RequestMethod.GET)
    public ResponseDTO provincePage() {
        List<Province> provinceList = provinceService.list();
        return ResponseDTO.success(provinceList);
    }

    @RequestMapping(value = "/{provinceCode}/city", name = "根据省份查询城市", method = RequestMethod.GET)
    public ResponseDTO cityPage(@PathVariable String provinceCode) {
        List<City> cities = cityService.list(provinceCode);
        return ResponseDTO.success(cities);
    }

    @RequestMapping(value = "/{cityCode}/area", name = "根据城市查询城区县", method = RequestMethod.GET)
    public ResponseDTO areaPage(@PathVariable String cityCode) {
        List<Area> areas = areaService.list(cityCode);
        return ResponseDTO.success(areas);
    }
}
